﻿namespace Moe.ECamel.Common.Entities
{
	using System;
	using System.ComponentModel;

	public partial class Employee : IEditableObject
	{
		public string Username
		{
			get { return this.User.Username; }
		}
		public string FirstName
		{
			get { return this.User.FirstName; }
		}
		public string LastName
		{
			get { return this.User.LastName; }
		}

		public ECamelError Validate()
		{
			// Validate user:
			ECamelError userError = this.User.Validate();
			if (userError != null)
				return userError;

			// Validate salary:
			if (this.Salary < 0)
				return new ECamelError(MessageIds.EmployeeInvalidNegativeSalary);

			return null;
		}

		#region IEditableObject Members

		private Employee _originalEntity = null;

		public void BeginEdit()
		{
			if (this._originalEntity == null)
			{
				// Initialize original library 
				this._originalEntity = new Employee();
				// Copy editable properties values:
				this._originalEntity._Salary = this._Salary;
			}
		}

		public void CancelEdit()
		{
			if (this._originalEntity != null)
			{
				// Restore properties:
				this._Salary = this._originalEntity._Salary;
				// Reset original values:
				this._originalEntity = null;
			}
		}

		public void EndEdit()
		{
			// Reset original values:
			this._originalEntity = null;
		}

		#endregion
	}
}